using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
	public static PoolRulesBase Rules;

	public static Canvas CurrentUIRoot;

	public static Canvas WindowCanvas;

	public static GameType GType;

	public int m_TargetFream = 300;

	[SerializeField]
	private LevelData m_DebugLevelData;

	private void Awake()
	{
		Application.targetFrameRate = 0;//m_TargetFream;
		PoolRulesBase.onGameOver = (Delegate1Args<IPlayer>)Delegate.Combine(PoolRulesBase.onGameOver, new Delegate1Args<IPlayer>(OnGameOver));
	}

	private void OnDestroy()
	{
		PoolRulesBase.onGameOver = (Delegate1Args<IPlayer>)Delegate.Remove(PoolRulesBase.onGameOver, new Delegate1Args<IPlayer>(OnGameOver));
	}

	private void Start()
	{
		switch (GType)
		{
			case GameType.QuickFire:
				BaseUIController.topMenu = SupportTools.AddChild<TopMenuQuickFire>(BaseUIController.TopMenuRoot.gameObject, "UI/BattleScene/TopMenuQuickFire");
				Rules = base.gameObject.AddComponent<PoolRulesQuickFire>();
				break;
			case GameType.Standard:
				BaseUIController.topMenu = SupportTools.AddChild<TopMenuStandard>(BaseUIController.TopMenuRoot.gameObject, "UI/BattleScene/TopMenuStandard");
				Rules = base.gameObject.AddComponent<PoolRulesStandard>();
				break;
			case GameType.Mission:
				BaseUIController.topMenu = SupportTools.AddChild<TopMenuMission>(BaseUIController.TopMenuRoot.gameObject, "UI/BattleScene/TopMenuMission");
				Rules = base.gameObject.AddComponent<PoolRulesMission>();
				break;
			case GameType.AI:
				BaseUIController.topMenu = SupportTools.AddChild<TopMenuStandard>(BaseUIController.TopMenuRoot.gameObject, "UI/BattleScene/TopMenuMultipleAI");
				Rules = base.gameObject.AddComponent<PoolRulesMultiple>();
				break;
		}
		BaseUIController.topMenu.transform.localScale = new Vector3(0.87f, 0.87f, 0.87f);
		Rules.SetPlayers(BaseUIController.topMenu.GetPlayers());
	}

	private void OnGameOver(IPlayer player)
	{
		if (!AdManager1.instance.ShieldAddress)
		{
			CheckTouch.Show(delegate
			{
				GameOver(player);
			});
		}
		else
		{
			AdManager.single.ShowNative();
			GameOver(player);
		}
	}

	private void GameOver(IPlayer player)
	{
		if (GType == GameType.AI)
		{
			GameStatistics.MarkAIBattleCount(1);
			if (!(player is AIPlayer))
			{
				GameStatistics.MarkAIBattleWins(1);
			}
		}
		Rules.State = GlobalState.GAMEOVER;
	}
}
